import HTTP from "../utils/require";
import Config from '../utils/config'
export default class IndexModel extends HTTP {
  // openid
  getOpenId(code) {
    return this.request({
      url: 'AAAWeChat/GetMyOpenID.ashx',
      data: {
        code
      }
    }).catch(console.error)
  }
  // 用户信息上传
  updateUserInfo(Openid, Info) {
    return this.request({
      url: 'AAAWeChat/ishavethisUserByopenid.ashx',
      data: {
        Openid,
        Comeform: 'XCX',
        WeChat_Id: 1,
        Info,
      }
    }).catch(console.error)
  }
  // 首页资讯 & id 详情
  // TableName=jyZixun&Column=Zixun_Id,Zixun_Title&PageIndex=1&PageSize=3&OrderBy=Zixun_Id desc
  getIndexInfo(id) {
    let data = id ? {
      TableName: 'jyZixun',
      ISwhereSql: 1,
      Where: `Zixun_Id=${id}`,
    } : {
        TableName: 'jyZixun',
        Column: 'Zixun_Id,Zixun_Title',
        PageIndex: 1,
        PageSize: 4,
        OrderBy: 'Zixun_Id desc',
      };
    return this.request({
      url: 'AAAWeChat/Wx_GetJYDaohangTableManager.ashx',
      data,
    }).catch(console.error)
  }

  // 收藏的网站
  GetCollectWebsite(PageIndex, id = 4) {
    return this.request({
      url: 'AAAWeChat/Wx_GetJYDaohangTableManager.ashx',
      data: {
        TableName: 'jyCompany',
        ISwhereSql: 1,
        Where: `companyID in (select Product_Id from jyUserFavor where WeChat_Id=1 and Enable=1 and Collection_Type=1 and Product_type=1 and WUser_Id=${id})`,
        PageSize: Config.PageSize,
        PageIndex,
        // Column: '',
      }
    }).catch(console.error)
  }
  // 收藏的资讯
  GetCollectInfo(PageIndex, id = 4) {
    return this.request({
      url: 'AAAWeChat/Wx_GetJYDaohangTableManager.ashx',
      data: {
        TableName: 'jyZixun',
        ISwhereSql: 1,
        Where: `Zixun_Id in(select Product_Id from jyUserFavor where WeChat_Id=1 and Enable=1 and Collection_Type=1 and Product_type=2 and WUser_Id=${id})`,
        PageSize: Config.PageSize,
        PageIndex,
        // Column: '',
      }
    }).catch(console.error)
  }
  // 收藏的锦囊
  GetCollectPackage(PageIndex, id = 4) {
    return this.request({
      url: 'AAAWeChat/Wx_GetJYDaohangTableManager.ashx',
      data: {
        TableName: 'jyJinnang',
        ISwhereSql: 1,
        Where: `Jinnang_Id in (select Product_Id from jyUserFavor where WeChat_Id=1 and Enable=1 and Collection_Type=1 and Product_type=3 and WUser_Id=${id})`,
        PageSize: Config.PageSize,
        PageIndex,
        // Column: '',
      }
    }).catch(console.error)
  }

  // 资讯top5
  getInfoTop5() {
    return this.request({
      url: 'AAAWeChat/Wx_GetJYDaohangTableManager.ashx',
      data: {
        TableName: 'jyZixun',
        Column: 'Zixun_Id,Zixun_Title',
        PageIndex: 1,
        PageSize: 5,
        OrderBy: 'Zixun_Redu desc',
      }
    }).catch(console.error)
  }

  // 首页分类 && 分类名称
  getIndexClassify(id = 1) {
    return this.request({
      url: 'AAAWeChat/Wx_GetIndexShowLowerpart.ashx',
      data: {
        WeChat_Id: id,
      }
    }).catch(console.error)
  }

  // =====================================
  // 分类选项数据
  getClassifyOption(type) { // chanpinfeilei shangyemoshifenlei fazhanfangxiang nianlingfanwei
    return this.request({
      url: 'AAAWeChat/Wx_GetJYDaohangTableManager.ashx',
      data: {
        TableName: 'jyFenlei',
        Column: 'fenlei',
        ISwhereSql: 1,
        Where: `ziduan='${type}'`,
      }
    }).catch(console.error)
  }
  // 公司列表(暂没用)
  getClassifyCompanyList(PageIndex) {
    return this.request({
      url: 'AAAWeChat/Wx_GetJYDaohangTableManager.ashx',
      data: {
        TableName: 'jyCompany',
        PageIndex,
        PageSize: Config.PageSize,
      }
    }).catch(console.error)
  }
  // 标题
  getTitleDesc(id = 4) {
    return this.request({
      url: 'AAAWeChat/getjyCompanyImportantShowEdit.ashx',
      data: {
        WUser_Id: id,
        WeChat_Id: 1,
        UserQuestion: '',
      }
    }).catch(console.error)
  }
  // 公司详情
  getClassifyCompanyList(id) {
    return this.request({
      url: 'AAAWeChat/GetTableInfoByPKId.ashx',
      data: {
        TableName: 'jyCompany',
        PKId: id,
      }
    }).catch(console.error)
  }
  // 查询
  queryCompanyInfo(PageIndex, chanpinfeilei, shangyemoshifenlei, fazhanfangxiang, nianlingfanwei, WeChat_Id = 1) {
    let data = {};
    let param = { chanpinfeilei, shangyemoshifenlei, fazhanfangxiang, nianlingfanwei };
    for (let key in param) {
      if (param[key]) {
        data[key] = param[key];
      }
    }
    return this.request({
      url: 'AAAWeChat/GetjyCompanyByWhere.ashx',
      data: Object.assign({
        WeChat_Id,
        PageIndex,
        PageSize: Config.PageSize,
        Column: 'description,companyLogo,didian,lunci,companyName,gongsbianhao,companyID',
      }, data)
    }).catch(console.error)
  }
  // =====================================
  // 资讯信息
  getInformationSum(PageIndex) {
    return this.request({
      url: 'AAAWeChat/Wx_GetJYDaohangTableManager.ashx',
      data: {
        TableName: 'jyZixun',
        Column: 'Zixun_Id,Zixun_Title,Zixun_StartTime,Zixun_Content',
        PageIndex,
        PageSize: Config.PageSize,
        OrderBy: 'Zixun_Id desc',
      }
    }).catch(console.error)
  }

  // 锦囊
  getPackageSum(PageIndex) {
    return this.request({
      url: 'AAAWeChat/Wx_GetJYDaohangTableManager.ashx',
      data: {
        TableName: 'jyJinnang',
        // Column: '',
        PageIndex,
        PageSize: Config.PageSize,
        // OrderBy: 
      }
    }).catch(console.error)
  }
  // 锦囊详情
  getPackageDetail(id) {
    return this.request({
      url: 'AAAWeChat/Wx_GetJYDaohangTableManager.ashx',
      data: {
        TableName: 'jyJinnang',
        ISwhereSql: 1,
        Where: `Jinnang_Id=${id}`,
      }
    }).catch(console.error)
  }
  // 建议
  uploadSuggest(UserQuestion, id = 4, wId = 1) {
    return this.request({
      url: 'AAAWeChat/AddUserQuestion.ashx',
      data: {
        WUser_Id: id,
        WeChat_Id: wId,
        UserQuestion,
      }
    }).catch(console.error)
  }

  /**
   * 是否收藏
   * @param {String} pId 主键ID
   * @param {String} type 收藏类型 1 jyCompany(网站) 2 jyZixun 3 jyJinnang
   * @param {String} id 用户ID
   * @param {String} wId 微信Id 默认
   */
  judgeFavor(pId, type, id = '4', wId = '1') {
    return this.request({
      url: 'AAAWeChat/GetIsMark.ashx',
      data: {
        Product_type: type,
        PKId: pId,
        WUser_Id: id,
        WeChat_Id: wId,
      }
    }).catch(console.error)
  }
  /**
   * 收藏和转发
   * @param {String} type 收藏的类型 1-> 收藏 2-> 转发
   * @param {String} pType 目标类型 1 网站 2 资讯 3 锦囊
   * @param {String} pId 主键
   * @param {Boolean} flag true Add false Delete
   * @param {String} id 用户Id
   * @param {String} wId 微信Id 默认
   */
  favor(type, pType, pId, flag, id = '4', wId = '1') {
    return this.request({
      url: 'AAAWeChat/OperationUserFavor.ashx',
      data: {
        WeChat_Id: wId,
        WUser_Id: id,
        Collection_Type: type,
        Product_type: pType,
        Product_Id: pId,
        Action: flag ? 'Add' : 'Delete',
      }
    }).catch(console.error)
  }

  websiteIntro() {
    return this.request({
      url: 'AAAWeChat/Wx_GetJYDaohangTableManager.ashx',
      data: {
        TableName: 'Base_WeChat',
        Where: 'WeChat_Id=1',
        ISwhereSql: 1,
        Column: 'Description,Business_Contact,Ev_Img',
      }
    }).catch(console.error)
  }
}